package com.itogis.rest.controler;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;


/**
 * 角色用户
 * 
 * @author Administrator
 * 
 */
@Controller
@RequestMapping("/role")
public class RoleUserControler extends CommomsControler{


	/**
	 * 添加用户
	 * @param request
	 * @param response
	 * @param roleid
	 * @param userid
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/addUser")
	public ModelAndView addUser(HttpServletRequest request,
			HttpServletResponse response, String roleid, String userid)
			throws IOException {
		boolean bool = roleService.addUser(roleid, userid);
		StringBuffer bf = new StringBuffer();
		String path = request.getContextPath();
		bf.append("<script>");
		bf.append("parent.location.href=parent.location.href;");
		bf.append("window.location.href='" + path
				+ "/ShowReport.wx?PAGEID=addRoleUser&REPORTID=list&roleid=" + roleid + "'");
		bf.append("</script>");
		response.getWriter().write(bf.toString());
		return null;
	}

	/**
	 * 删除用户
	 * @param request
	 * @param response
	 * @param roleid
	 * @param userid
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/deleteUser")
	public String deleteUser(HttpServletRequest request,
			HttpServletResponse response, String roleid, String userid)
			throws IOException {
		boolean bool = roleService.deleteUser(roleid, userid);
		response.getWriter().write((bool) ? "true" : "false");
		return null;
	}

	/**
	 * 添加权限
	 * 
	 * @param request
	 * @param response
	 * @param roleid
	 *            :角色iD
	 * @param rightid
	 *            ：权限ID
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/addRight")
	public ModelAndView addRight(HttpServletRequest request,
			HttpServletResponse response, String roleid, String rightid)
			throws IOException {
		boolean bool = roleService.addRight(roleid, rightid);
		StringBuffer bf = new StringBuffer();
		String path = request.getContextPath();
		bf.append("<script>");
		bf.append("parent.location.href=parent.location.href;");
		bf.append("window.location.href='" + path
				+ "/ShowReport.wx?PAGEID=addRoleRight&REPORTID=list&roleid=" + roleid + "'");
		bf.append("</script>");
		response.getWriter().write(bf.toString());
		return null;
	}

}
